package com.hmall.item.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hmall.common.dto.PageDTO;
import com.hmall.item.mapper.ItemMapper;
import com.hmall.item.pojo.Item;
import com.hmall.item.service.ItemService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemServiceImpl extends ServiceImpl<ItemMapper, Item> implements ItemService {

    @Override
    public PageDTO<Item> findList(Integer page, Integer size) {

        //1. 设置分页条件
        Page<Item> p = new Page<>(page, size);

        //2. 设置业务条件
        LambdaQueryWrapper<Item> wrapper = new LambdaQueryWrapper<>();

        //3. 执行查询
        this.page(p, wrapper);
        List<Item> records = p.getRecords();

        //4. 返回结果
        return new PageDTO<Item>(p.getTotal(), p.getRecords());
    }
}
